package com.changgou.web.order.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.order.feign.CartFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: HuangFu
 * @Date: 2020/2/15 10:33
 * @Description:
 */
@Controller
@RequestMapping("/wcart")
public class CartController {

    @Autowired
    private CartFeign cartFeign;

    @GetMapping("/list")
    public String list(Model model){
        Result result = cartFeign.list();
        Map map = (Map) result.getData();
        model.addAttribute("items",map);
        return "cart";
    }

    @GetMapping("/add")
    @ResponseBody
    public Result add(@RequestParam("id")String skuId,@RequestParam("num") Integer num){
        cartFeign.add(skuId, num);
        Result list = cartFeign.list();
        Map map = (Map) list.getData();
        return new Result(true, StatusCode.OK,"购物车添加成功",map);
    }

}
